package com.ruoyi.client.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.supply.domain.News;
import com.ruoyi.supply.enums.DfStatusEnum;
import com.ruoyi.supply.service.impl.AdSpotService;
import com.ruoyi.supply.service.impl.NewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author huangxiong
 * @date 2025/06/09 21:03
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/client/adNews")
@Api(tags = "客户端头部模块")
public class AdNewsController extends BaseController {

    private final AdSpotService adSpotService;
    private final NewsService newsService;

    @GetMapping("/banner")
    @ApiOperation("获取 banner")
    @Anonymous
    public AjaxResult getBanner(){
        return AjaxResult.success(adSpotService.getBanner());
    }

    @GetMapping("/news")
    @ApiOperation("获取 news")
    @Anonymous
    public AjaxResult getNews(@RequestParam(required = false) Integer size){
        return AjaxResult.success(newsService.getClientNews(size));
    }

    @GetMapping("/news/{id}")
    @ApiOperation("获取 news 详情")
    @Anonymous
    public AjaxResult getNewsDetail(@PathVariable("id")Long id){
        return AjaxResult.success(newsService.getByClientId(id));
    }

    /**
     * 查询快讯列表
     */
    @GetMapping("/list")
    @ApiOperation("查询快讯")
    @Anonymous
    public TableDataInfo list(News news)
    {
        news.setStatus(DfStatusEnum.DF.getCode());
        startPage();
        List<News> list = newsService.selectNewsList(news);
        return getDataTable(list);
    }

}
